package daoMySQL;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import daoDataFactory.DbObject;
import daoInterface.DaoIMenu;
import domijn.Menu;

public class MySQLMenu extends DbObject implements DaoIMenu{

	private Statement stmt = null;
	private ResultSet rs = null;
	
	private static MySQLMenu instance;
	
	public static DaoIMenu instance(){
		if (instance == null) {
			 instance = new MySQLMenu();
		}
		return instance;
	}
	
	@Override
	public void save(Menu menu) {
		
		
	}
	@Override
	public void update(Menu m) {
		String sqlUpdate = "UPDATE"
				+ "		`menu`"
				+ "	SET"
				+ "		`menu`.`MenuNaam` ='"+ m.getMenuNName()+"'"
				+ "	WHERE"
				+ "		`menu`.`MenuNaam` ='"+ m.getMenuName()+"'"; 
		try{
			stmt = openConnection().createStatement();
			stmt.executeUpdate(sqlUpdate);
					}
		catch(Exception e1){
			
		}}
		
	

	

	@Override
	public ArrayList<Menu> loadall() {
		ArrayList<Menu>menus = new ArrayList<Menu>();
		String sqlloadall = "Select * from `menu` ORDER BY `menu`.`MenuID` desc";
		try {
			Menu m;
			stmt = openConnection().createStatement();
			rs = stmt.executeQuery(sqlloadall);
			while(rs.next()){
				m = new Menu(rs.getInt(1),rs.getString(2));
				menus.add(m);
			}} 
		catch (Exception e) {
		}
	return menus;
	}

	


}